<?php
class loginController extends adminController{

	public function index(){
		$this->display();
	}

	public function login(){
		if(empty($_POST['username'])||empty($_POST['password'])){
            $this->msg('帐号信息输入错误!',0);
        }
        //获取帐号信息
        $info=model('admin_user')->info(in($_POST['username']));
        //进行帐号验证
        if(empty($info)){
            $this->msg('登录失败! 无此管理员帐号!',0);
        }
        if($info['password']<>md5($_POST['password'])){
            $this->msg('登录失败! 密码错误!',0);
        }
        if($info['status']==0){
            $this->msg('登录失败! 帐号已禁用!',0);
        }
        //更新帐号信息
        $data['logintime']=time();
        $data['ip']=get_client_ip();
        $data['loginnum']=intval($info['loginnum'])+1;
        $data['uid']=$info['uid'];
        model('admin_user')->edit($data);
        //更新登录记录
        model('admin_log')->add($info);
        //设置登录信息
        $this->setLogin($info);
        $this->msg('登录成功!',1);
	}

    //退出
    public function logout(){
        $this->clearLogin(url('admin/index/index'));
    }
}